package cn.ft.eurekaserviceinvoker;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@RestController
@Configuration
public class InvokerController {

    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }

    @RequestMapping(value = "/router/{personId}")
    public Map router(@PathVariable Integer personId) {
        Map<String, Object> person = personClient.findPerson(personId);
        return person;
    }

    @Autowired
    private PersonClient personClient;

    @RequestMapping(value = "/invokeHello")
    public String invokeHello() {
        return personClient.hello();
    }

}